<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>二次衔接上报新增</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/voiceinteraction/voiceinteraction.css" rel="stylesheet" type="text/css"/>
    <style>
        .discell {
            text-align: right;
            width: 30%;
        }

        .input {
            width: 70%;
        }
        table
        { border-collapse: separate; border-spacing: 10px; }
    </style>
</head>
<body>
<div class="mini-fit" style="margin-bottom: 40px;">
    <form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <!-- 用户 编辑框START-->
        <div id="editform" class="form" style="padding:10px;">
            <input name="id" id="id" class="mini-hidden" style="width: 100%;" readonly value="${id!''}"/>
            <input name="priNum" id="priNum" class="mini-hidden" style="width: 100%" readonly value="${priNum!''}"/>
            <input name="secondstate" id="secondstate" class="mini-hidden" style="width: 100%" readonly value="${secondstate!''}"/>
            <table class="form-table" align="center" >
                <tr>
                    <td style="font-weight: bold;text-align: left">看守所信息:</td>
                </tr>
                <tr>
                    <td class="discell"><font id="jylxrfont" color="#dc143c">*</font>看守所联系人:</td>
                    <td class="input">
                        <input name="jylxr" id="jylxr" class="mini-textbox" required="true" value="${jylxr!''}" style="width: 100%"
                               emptyText="请输入看守所联系人"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell">看守所手机号码:</td>
                    <td class="input">
                        <input name="jyphone" id="jyphone" class="mini-textbox"  value="${jyphone!''}" style="width: 100%"
                               emptyText="请输入手机号码" onvaluechanged="checkPhone(2)" />
                    </td>
                </tr>
                <tr>
                    <td class="discell">看守所固话:</td>
                    <td class="input">
                        <input name="jytel" id="jytel" class="mini-textbox" value="${jytel!''}" style="width: 100%"
                               emptyText="请输入固定电话" onvaluechanged="checkPhone(1)" />
                    </td>
                </tr>
                <tr>
                    <td class="discell">上传附件:</td>
                    <td class="input">
                        <input type="button" onclick="onFileUpload()" value="上传" style="width: 150px"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font id="jyyjfont" color="#dc143c">*</font>看守所意见:</td>
                    <td class="input">
                        <input name="jyyj" id="jyyj" class="mini-textarea" value="${jyyj!''}" required="true" style="width: 100%" />
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold;text-align: left">监管总队信息:</td>
                </tr>
                <tr>
                    <td class="discell"><font id="jyjyjfont" color="#dc143c">*</font>监管总队意见:</td>
                    <td class="input">
                        <input name="jyjyj" id="jyjyj" class="mini-textarea"  value="${jyjyj!''}" required="true" style="width: 100%" />
                    </td>
                </tr>
                <tr>
                    <td style="font-weight: bold;text-align: left">司法厅信息:</td>
                </tr>
                <tr>
                    <td class="discell">
                        <font id="flagfont" color="#dc143c" hidden>*</font>二次衔接方式:
                    </td>
                    <td class="input">
                        <input name="flag" id="flag" class="mini-radiobuttonlist"
                               data="[{ id: 1, name: '本省协调' },{ id: 2, name: '转到上报业务协调' }]"
                               textField="name" valueField="id" value="1" required="true" onvaluechanged="flagValueChanged()"/>
                    </td>
                </tr>
                <tr id="sfsinfo">
                    <td class="discell" rowspan="4">
                        <font id="addrfont" color="#dc143c" hidden>*</font>司法所地址:
                    </td>
                    <td class="input">
                        <input id="nativepro" name="nativepro" class="mini-combobox" required="true" emptyText="省份"
                               textfield="codeName" valueField="codeId"
                               onclick="onDeptChanged('nativepro')" onvaluechanged="onValueChanged('nativepro')"/>
                        <input id="nativecity" name="nativecity" class="mini-combobox" required="true" emptyText="市"
                               textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativecity')"
                               onvaluechanged="onValueChanged('nativecity')" />
                        <input id="nativecou" name="nativecou" class="mini-combobox" required="true" emptyText="县"
                               textfield="codeName" valueField="codeId" onclick="onDeptChanged('nativecou')"
                               onvaluechanged="onValueChanged('nativecou')" />
                        <input id="nativevill" name="nativevill" class="mini-combobox" emptyText="街道"
                               textfield="codeName" valueField="codeId"onclick="onDeptChanged('nativevill')" required="true"/>
                    </td>
                </tr>
                <tr id="sft1">
                    <td class="discell"><font id="sftlxrfont" color="#dc143c" hidden>*</font>司法厅联系人:</td>
                    <td class="input">
                        <input name="sftlxr" id="sftlxr" class="mini-textbox" value="${sftlxr!''}" required="true" style="width: 100%"
                               emptyText="请输入司法厅联系人" />
                    </td>
                </tr>
                <tr id="sft2">
                    <td class="discell">司法厅联系方式:</td>
                    <td class="input">
                        <input name="sftphone" id="sftphone" class="mini-textbox" value="${sftphone!''}"  style="width: 100%"
                               emptyText="请输入手机号码"  />
                    </td>
                </tr>
                <tr id="sft3">
                    <td class="discell">司法厅联系方式:</td>
                    <td class="input">
                        <input name="sfttel" id="sfttel" class="mini-textbox" value="${sfttel!''}"  style="width: 100%"
                               emptyText="请输入固定电话(区号-区段号码)"  />
                    </td>
                </tr>
                <tr id="sft4">
                    <td class="discell"><font id="sftyjfont" color="#dc143c" hidden>*</font>司法厅意见:</td>
                    <td class="input">
                        <input name="sftyj" id="sftyj" class="mini-textarea" value="${sftyj!''}" style="width: 100%" required="true"/>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<div style="position: absolute;bottom: 0;line-height:40px;width: 100%;border-top:1px solid #dfdfdf;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()" style="font-size: 15px">保存</a>
</div>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");

    var jylxr = mini.get("jylxr");
    var jyphone = mini.get("jyphone");
    var jytel = mini.get("jytel");
    var jyyj = mini.get("jyyj");
    var jyjyj = mini.get("jyjyj");
    var sftlxr = mini.get("sftlxr");
    var sftphone = mini.get("sftphone");
    var sfttel = mini.get("sfttel");
    var sftyj = mini.get("sftyj");
    var flag = mini.get("flag");
    var nativepro = mini.get("nativepro");
    var nativecity = mini.get("nativecity");
    var nativecou = mini.get("nativecou");
    var nativevill = mini.get("nativevill");
    var secondstate = mini.get("secondstate");

    var level = ${level!''};
    //监狱
    if(level=='01'){
        document.getElementById("jylxrfont").hidden=false;
        document.getElementById("jyyjfont").hidden=false;
    }
    if(level=='05'){
        document.getElementById("jylxrfont").hidden=false;
        document.getElementById("jyyjfont").hidden=false;
    }
    if(level=='09'){
        document.getElementById("jyjyjfont").hidden=false;
    }
    if(level=='15'){
        document.getElementById("jyjyjfont").hidden=false;
    }
    if(level=='06'){
        document.getElementById("addrfont").hidden=false;
        document.getElementById("sftlxrfont").hidden=false;
        document.getElementById("sftyjfont").hidden=false;
    }

    /**
     * 保存数据
     */
    function saveData(){
        var level = ${level!''};
        var phone = jyphone.getValue();
        var telPhone = jytel.getValue();
        var newPhone = checkTelAndPhone(telPhone,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("手机号码或固话有误，请重填");
            return;
        }
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        var json = mini.encode(data);
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '加载中...'
        });
        $.ajax({
            url: "/azbj/ysfryxj/xjreport/save",
            data: {data: json},
            type: "post",
            success: function (success) {
                mini.unmask(document.body);
                $('.data-loading').css('display','none');
                if (success.code == 1) {
                    var data = mini.decode(success.data);
                    form.setData(data);
                    nativepro.setData([{codeId: data.nativepro, codeName: data.nativeproName}]);
                    nativecity.setData([{codeId: data.nativecity, codeName: data.nativecityName}]);
                    nativecou.setData([{codeId: data.nativecou, codeName: data.nativecouName}]);
                    nativevill.setData([{codeId: data.nativevill, codeName: data.nativevillName}]);
                    mini.alert("保存成功","成功",window.CloseOwnerWindow);
                } else {
                    mini.alert("保存失败");
                }
            }, error: function () {
                mini.unmask(document.body);
                mini.alert("系统异常");
            }
        })
    }

    // 上传附件
    function onFileUpload() {//taskId为2是衔接信息的附件
        var nouploadflag = "5000";
        commonEdit("/upload/user/uploadAppendixfileSecXj/view?1=1&id=${xjxxId!''}&priNum=${priNum!''}&taskId=35"+"&nouploadflag="+nouploadflag,null, null,600, 400, true,true,true);
    }

    /**
     * 验证手机号码
     * @param e
     */
    function checkPhone(e){
        var phone = jyphone.getValue();
        var telPhone = jytel.getValue();
        if (e == '1') {
            if(!validateTel(telPhone)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (e == '2') {
            if(!validatePhone1(phone)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }

    /**
     * 本省协调和跨省业务页面展示
     */
    function flagValueChanged(){
        var f= flag.getValue();
        if(f == "1"){
            document.getElementById("sfsinfo").style.display = 'table-row';
            document.getElementById("sft1").style.display = 'none';
            document.getElementById("sft2").style.display = 'none';
            document.getElementById("sft3").style.display = 'none';
            document.getElementById("sft4").style.display = 'none';
        }else if(f == "2"){
            document.getElementById("sfsinfo").style.display = 'none';
            document.getElementById("sft1").style.display = 'table-row';
            document.getElementById("sft2").style.display = 'table-row';
            document.getElementById("sft3").style.display = 'table-row';
            document.getElementById("sft4").style.display = 'table-row';
        }
    }

    var urltemp = "/azbj/getCodeDetail/?codeType=2_1&codeId=-2";
    function onDeptChanged(e) {
        if ("nativepro" == e) {
            nativepro.setData([{codeId: "${provinceCode!''}", codeName: "${provinceName!''}"}]);
            nativepro.select(0);
        }

        if ("nativecity" == e) {
            var value = nativecity.getValue();
            if(nativepro.getValue()==""){
                nativepro.setUrl(urltemp);
                nativepro.setValue("");
                nativecou.setUrl(urltemp);
                nativecou.setValue("");
                nativevill.setUrl(urltemp);
                nativevill.setValue("");
            }
            var codeId = nativepro.getValue();
            nativecity.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            nativecity.setUrl(url);
            if(value!=''){
                nativecity.setValue(value);
            } else {
                nativecity.select(0);
            }
        }

        if ("nativecou" == e) {
            var value = nativecou.getValue();
            if(nativecity.getValue()==""){
                nativecou.setUrl(urltemp);
                nativecou.setValue("");
                nativevill.setUrl(urltemp);
                nativevill.setValue("");
                return;
            }
            var codeId = nativecity.getValue();
            nativecou.setValue("");
            var url = "/azbj/getCodeDetail/?codeType=2_1&codeId=" + codeId;
            nativecou.setUrl(url);
            if(value!=''){
                nativecou.setValue(value);
            } else {
                nativecou.select(0);
            }
        }

        if ("nativevill" == e) {
            var value = nativevill.getValue();
            if(nativecou.getValue()==""){
                nativevill.setUrl(urltemp);
                nativevill.setValue("");
                return;
            }
            var parent_code = nativecou.getValue();
            nativevill.setValue("");
            var url = "/azbj/getCodeDetail?codeType=2_1&codeId=" + parent_code;
            nativevill.setUrl(url);
            if(value!=''){
                nativevill.setValue(value);
            } else {
                nativevill.select(0);
            }
        }
    }

    function onValueChanged(e) {
        if ("nativepro" == e) {
            nativecity.setValue("");
            nativecou.setValue("");
            nativevill.setValue("");
        }

        if ("nativecity" == e) {
            nativecou.setValue("");
            nativevill.setValue("");
        }

        if ("nativecou" == e) {
            nativevill.setValue("");
        }

    }

    window.onload = function (){
        flagValueChanged();
        var level = ${level!''};
        if (level == "1") { // 监狱
            jyjyj.disable();
            sftlxr.disable();
            sftphone.disable();
            sfttel.disable();
            sftyj.disable();
            flag.disable();
            nativepro.disable();
            nativecity.disable();
            nativecou.disable();
            nativevill.disable();
        }else if (level == "5") { // 社矫
            jyjyj.disable();
            sftlxr.disable();
            sftphone.disable();
            sfttel.disable();
            sftyj.disable();
            flag.disable();
            nativepro.disable();
            nativecity.disable();
            nativecou.disable();
            nativevill.disable();
        } if (level == "2") { // 看守所
            jyjyj.disable();
            sftlxr.disable();
            sftphone.disable();
            sfttel.disable();
            sftyj.disable();
            flag.disable();
            nativepro.disable();
            nativecity.disable();
            nativecou.disable();
            nativevill.disable();
        }//监狱局
        else if(level == "9"){
            jylxr.disable();
            jyphone.disable();
            jytel.disable();
            jyyj.disable();
            sftlxr.disable();
            sftphone.disable();
            sfttel.disable();
            sftyj.disable();
            flag.disable();
            nativepro.disable();
            nativecity.disable();
            nativecou.disable();
            nativevill.disable();
        }//社矫管理局
        else if(level == "15"){
            jylxr.disable();
            jyphone.disable();
            jytel.disable();
            jyyj.disable();
            sftlxr.disable();
            sftphone.disable();
            sfttel.disable();
            sftyj.disable();
            flag.disable();
            nativepro.disable();
            nativecity.disable();
            nativecou.disable();
            nativevill.disable();
        }//监管总队
        else if(level == "4"){
            jylxr.disable();
            jyphone.disable();
            jytel.disable();
            jyyj.disable();
            sftlxr.disable();
            sftphone.disable();
            sfttel.disable();
            sftyj.disable();
            flag.disable();
            nativepro.disable();
            nativecity.disable();
            nativecou.disable();
            nativevill.disable();
        } else if(level == "6"){
            jylxr.disable();
            jyphone.disable();
            jytel.disable();
            jyyj.disable();
            jyjyj.disable();
            if(secondstate.getValue() == "6"){
                flag.setValue("1");
                flag.disable();
            }
        }else{
            jylxr.disable();
            jyphone.disable();
            jytel.disable();
            jyyj.disable();
            jyjyj.disable();
            sftlxr.disable();
            sftphone.disable();
            sfttel.disable();
            sftyj.disable();
            flag.disable();
            nativepro.disable();
            nativecity.disable();
            nativecou.disable();
            nativevill.disable();
        }
    }
</script>
</body>
</html>